package com.zkingsoft.actions.visitor;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zkingsoft.constraint.BaseController;
import com.zkingsoft.model.web.WebAd;
import com.zkingsoft.model.web.WebArticle;
import com.zkingsoft.model.web.WebArticleType;
import com.zkingsoft.pojo.AjaxResult;
import com.zkingsoft.pojo.PaginationVO;
import com.zkingsoft.services.web.WebAdService;
import com.zkingsoft.services.web.WebArticleService;
import com.zkingsoft.services.web.WebArticleTypeService;
import com.zkingsoft.util.WebUtil;

/**
 * 
 * @Description: 不需要登录可以访问的action
 * @author:姜友瑶
 * @date 2016年8月31日
 */
@Controller
public class Home extends BaseController {

	@Resource
	WebAdService webAdService;

	@Resource
	WebArticleService artService;

	@Resource
	WebArticleTypeService artTypeService;

	/**
	 * 
	 * @Description: 首页配置
	 * @author:姜友瑶
	 * @return 返回类型 String
	 * @date 2016年8月28日
	 */
	@RequestMapping(value = "/")
	public String redirect() {

		List<WebAd> lbt = webAdService.findAdByCloName("首页轮播大图");
		List<WebAd> yzkc = webAdService.findAdByCloName("优质课程");
		List<WebAd> mfkc = webAdService.findAdByCloName("免费课程");
		List<WebAd> jyzx = webAdService.findAdByCloName("就业资讯");
		List<WebAd> hzqy = webAdService.findAdByCloName("合作企业");
		List<WebAd> dkds = webAdService.findAdByCloName("大咖导师");
		List<WebAd> jyds = webAdService.findAdByCloName("精英导师");
		List<WebAd> hzyx = webAdService.findAdByCloName("合作院校");
		WebArticle webArticle = new WebArticle();
		WebArticleType type = new WebArticleType();
		type.setArtTypeName("新闻资讯");
		List<WebArticleType> types = artTypeService.findByModel(type);
		if (types.size() > 0) {
			webArticle.setArtTypeId(types.get(0).getArtTypeId());
		}
		PaginationVO pageVo = new PaginationVO();
		pageVo.setLimit(4);
		List<WebArticle> news = artService.findInPage(webArticle, pageVo);
		
		WebUtil.setRequestAttribute("news", news);
		WebUtil.setRequestAttribute("lbt", lbt);
		WebUtil.setRequestAttribute("yzkc", yzkc);
		WebUtil.setRequestAttribute("mfkc", mfkc);
		WebUtil.setRequestAttribute("jyzx", jyzx);
		WebUtil.setRequestAttribute("hzqy", hzqy);
		WebUtil.setRequestAttribute("dkds", dkds);
		WebUtil.setRequestAttribute("jyds", jyds);
		WebUtil.setRequestAttribute("hzyx", hzyx);

		

		return "/visitor/index";
	}

	@RequestMapping(value = "visitor/java")
	public String java() {

		WebAd banner = webAdService.findAdByCloNameOne("javaBanner图");

		WebAd kctxbt = webAdService.findAdByCloNameOne("java课程体系标题");
		List<WebArticle> kctx = artService.findByTypeName("java课程体系");
		WebArticle kc1 = new WebArticle();
		WebArticle kc2 = new WebArticle();
		WebArticle kc3 = new WebArticle();
		if (kctx.size() == 3) {
			kc1 = kctx.get(0);
			kc2 = kctx.get(1);
			kc3 = kctx.get(2);
		}

		WebAd kbbt = webAdService.findAdByCloNameOne("java开班标题");
		List<WebAd> bj = webAdService.findAdByCloName("JAVA+Android班");

		WebAd hq = webAdService.findAdByCloNameOne("java行情");

		List<WebAd> zp = webAdService.findAdByCloName("java作品");

		WebAd jybt = webAdService.findAdByCloNameOne("java就业标题");
		List<WebAd> jyxx = webAdService.findAdByCloName("java就业信息");

		WebAd xyq = webAdService.findAdByCloNameOne("java学员墙");
		WebUtil.setRequestAttribute("banner", banner);
		WebUtil.setRequestAttribute("kctxbt", kctxbt);
		WebUtil.setRequestAttribute("kc1", kc1);
		WebUtil.setRequestAttribute("kc2", kc2);
		WebUtil.setRequestAttribute("kc3", kc3);
		WebUtil.setRequestAttribute("kbbt", kbbt);
		WebUtil.setRequestAttribute("bj", bj);
		WebUtil.setRequestAttribute("hq", hq);
		WebUtil.setRequestAttribute("zp", zp);
		WebUtil.setRequestAttribute("jybt", jybt);
		WebUtil.setRequestAttribute("jyxx", jyxx);
		WebUtil.setRequestAttribute("xyq", xyq);

		return "/visitor/java";
	}

	@RequestMapping(value = "visitor/web")
	public String web() {

		WebAd banner = webAdService.findAdByCloNameOne("webBanner图");

		WebAd kctxbt = webAdService.findAdByCloNameOne("web课程体系标题");
		List<WebArticle> kctx = artService.findByTypeName("web课程体系");
		WebArticle kc1 = new WebArticle();
		WebArticle kc2 = new WebArticle();
		WebArticle kc3 = new WebArticle();
		WebArticle kc4 = new WebArticle();
		if (kctx.size() == 4) {
			kc1 = kctx.get(0);
			kc2 = kctx.get(1);
			kc3 = kctx.get(2);
			kc4 = kctx.get(3);
		}

		WebAd kbbt = webAdService.findAdByCloNameOne("web开班标题");
		List<WebAd> bj = webAdService.findAdByCloName("web前端班");

		WebAd hq = webAdService.findAdByCloNameOne("web行情");
		WebAd hq2 = webAdService.findAdByCloNameOne("web行情2");

		WebAd jybt = webAdService.findAdByCloNameOne("web就业标题");
		List<WebAd> jyxx = webAdService.findAdByCloName("web就业信息");

		WebAd xyq = webAdService.findAdByCloNameOne("web学员墙");
		WebUtil.setRequestAttribute("banner", banner);
		WebUtil.setRequestAttribute("kctxbt", kctxbt);
		WebUtil.setRequestAttribute("kc1", kc1);
		WebUtil.setRequestAttribute("kc2", kc2);
		WebUtil.setRequestAttribute("kc3", kc3);
		WebUtil.setRequestAttribute("kc4", kc4);
		WebUtil.setRequestAttribute("kbbt", kbbt);
		WebUtil.setRequestAttribute("bj", bj);
		WebUtil.setRequestAttribute("hq", hq);
		WebUtil.setRequestAttribute("hq2", hq2);
		WebUtil.setRequestAttribute("jybt", jybt);
		WebUtil.setRequestAttribute("jyxx", jyxx);
		WebUtil.setRequestAttribute("xyq", xyq);

		return "/visitor/web";
	}

	@RequestMapping(value = "visitor/game")
	public String game() {

		WebAd banner = webAdService.findAdByCloNameOne("游戏Banner图");

		WebAd kctxbt = webAdService.findAdByCloNameOne("游戏课程体系标题");
		WebAd kctx = webAdService.findAdByCloNameOne("游戏课程体系");
		/*
		 * List<WebArticle> kctx = artService.findByTypeName("game课程体系");
		 * 
		 * WebArticle kc1 = new WebArticle(); WebArticle kc2 = new WebArticle();
		 * WebArticle kc3 = new WebArticle(); if(kctx.size()==3){
		 * kc1=kctx.get(0); kc2=kctx.get(1); kc3=kctx.get(2); }
		 */

		WebAd kbbt = webAdService.findAdByCloNameOne("游戏开班标题");
		List<WebAd> bj = webAdService.findAdByCloName("游戏班");

		WebAd hq = webAdService.findAdByCloNameOne("游戏行情");
		WebAd hq2 = webAdService.findAdByCloNameOne("游戏行情2");

		List<WebAd> zp = webAdService.findAdByCloName("游戏作品");

		WebAd jybt = webAdService.findAdByCloNameOne("游戏就业标题");
		List<WebAd> jyxx = webAdService.findAdByCloName("游戏就业信息");

		WebAd xyq = webAdService.findAdByCloNameOne("游戏学员墙");
		WebUtil.setRequestAttribute("banner", banner);
		WebUtil.setRequestAttribute("kctxbt", kctxbt);
		WebUtil.setRequestAttribute("kctx", kctx);
		/*
		 * WebUtil.setRequestAttribute("kc2", kc2);
		 * WebUtil.setRequestAttribute("kc3", kc3);
		 */
		WebUtil.setRequestAttribute("kbbt", kbbt);
		WebUtil.setRequestAttribute("bj", bj);
		WebUtil.setRequestAttribute("hq", hq);
		WebUtil.setRequestAttribute("hq2", hq2);
		WebUtil.setRequestAttribute("zp", zp);
		WebUtil.setRequestAttribute("jybt", jybt);
		WebUtil.setRequestAttribute("jyxx", jyxx);
		WebUtil.setRequestAttribute("xyq", xyq);

		return "/visitor/game";
	}

	@RequestMapping(value = "visitor/gameui")
	public String gameui() {

		WebAd banner = webAdService.findAdByCloNameOne("uiBanner图");

		WebAd kctxbt = webAdService.findAdByCloNameOne("ui课程体系标题");

		List<WebArticle> kctx = artService.findByTypeName("UI游戏动漫课程体系");

		WebArticle kc1 = new WebArticle();
		WebArticle kc2 = new WebArticle();
		WebArticle kc3 = new WebArticle();
		WebArticle kc4 = new WebArticle();
		if (kctx.size() == 4) {
			kc1 = kctx.get(0);
			kc2 = kctx.get(1);
			kc3 = kctx.get(2);
			kc4 = kctx.get(3);
		}

		WebAd kbbt = webAdService.findAdByCloNameOne("ui开班标题");
		List<WebAd> bj = webAdService.findAdByCloName("ui游戏班");

		List<WebAd> zp = webAdService.findAdByCloName("ui作品");

		WebAd jybt = webAdService.findAdByCloNameOne("ui就业标题");
		List<WebAd> jyxx = webAdService.findAdByCloName("ui就业信息");

		WebAd xyq = webAdService.findAdByCloNameOne("ui学员墙");
		WebUtil.setRequestAttribute("banner", banner);
		WebUtil.setRequestAttribute("kctxbt", kctxbt);
		WebUtil.setRequestAttribute("kc1", kc1);
		WebUtil.setRequestAttribute("kc2", kc2);
		WebUtil.setRequestAttribute("kc3", kc3);
		WebUtil.setRequestAttribute("kc4", kc4);
		WebUtil.setRequestAttribute("kbbt", kbbt);
		WebUtil.setRequestAttribute("bj", bj);
		WebUtil.setRequestAttribute("zp", zp);
		WebUtil.setRequestAttribute("jybt", jybt);
		WebUtil.setRequestAttribute("jyxx", jyxx);
		WebUtil.setRequestAttribute("xyq", xyq);

		return "/visitor/gameui";
	}

	@RequestMapping(value = "visitor/job")
	public String job() {

		WebAd banner = webAdService.findAdByCloNameOne("jobBanner");

		WebAd ys = webAdService.findAdByCloNameOne("job8大优势");
		WebAd xcsp = webAdService.findAdByCloNameOne("job薪酬水平");

		List<WebAd> zpxql = webAdService.findAdByCloName("job招聘需求量");
		List<WebAd> wmdcl = webAdService.findAdByCloName("我们的承诺");
		List<WebAd> jydt = webAdService.findAdByCloName("就业动态");
		List<WebAd> lmsj = webAdService.findAdByCloName("六脉神剑");
		List<WebAd> qykb = webAdService.findAdByCloName("企业口碑");
		List<WebAd> xyfx = webAdService.findAdByCloName("学员分享");

		WebAd xyq = webAdService.findAdByCloNameOne("就业明星墙");

		WebUtil.setRequestAttribute("banner", banner);
		WebUtil.setRequestAttribute("ys", ys);
		WebUtil.setRequestAttribute("xcsp", xcsp);
		WebUtil.setRequestAttribute("zpxql", zpxql);
		WebUtil.setRequestAttribute("wmdcl", wmdcl);
		WebUtil.setRequestAttribute("jydt", jydt);
		WebUtil.setRequestAttribute("lmsj", lmsj);
		WebUtil.setRequestAttribute("xyq", xyq);
		WebUtil.setRequestAttribute("qykb", qykb);
		WebUtil.setRequestAttribute("xyfx", xyfx);

		return "/visitor/job";
	}

	/**
	 * 列表显示新闻资讯
	 */
	@RequestMapping(value = "visitor/findNews")
	public @ResponseBody AjaxResult showList(WebArticle webArticle, PaginationVO pageVo) {

		WebArticleType type = new WebArticleType();
		type.setArtTypeName("新闻资讯");
		List<WebArticleType> types = artTypeService.findByModel(type);
		if (types.size() > 0) {
			webArticle.setArtTypeId(types.get(0).getArtTypeId());
		}
		return showList(artService, webArticle, pageVo);
	}

	@RequestMapping(value = "visitor/news")
	public String news() {
		WebAd xwzx = webAdService.findAdByCloNameOne("新闻资讯banner");
		WebUtil.setRequestAttribute("xwzx", xwzx);
		return "/visitor/news";
	}

	/**
	 * 列表显示免费课程
	 */
	@RequestMapping(value = "visitor/findclass")
	public @ResponseBody AjaxResult findclass(WebArticle webArticle, PaginationVO pageVo) {

		WebArticleType type = new WebArticleType();
		type.setArtTypeName("免费课程");
		List<WebArticleType> types = artTypeService.findByModel(type);
		if (types.size() > 0) {
			webArticle.setArtTypeId(types.get(0).getArtTypeId());
		}
		return showList(artService, webArticle, pageVo);
	}

	/**
	 * 列表显示免费课程
	 */
	@RequestMapping(value = "visitor/findshare")
	public @ResponseBody AjaxResult findshare(WebArticle webArticle, PaginationVO pageVo) {

		WebArticleType type = new WebArticleType();
		type.setArtTypeName("学员分享");
		List<WebArticleType> types = artTypeService.findByModel(type);
		if (types.size() > 0) {
			webArticle.setArtTypeId(types.get(0).getArtTypeId());
		}
		return showList(artService, webArticle, pageVo);
	}

	@RequestMapping(value = "visitor/freeclass")
	public String freeclass() {
		WebAd xwzx = webAdService.findAdByCloNameOne("免费课程banner");
		WebUtil.setRequestAttribute("xwzx", xwzx);
		return "/visitor/freeclass";
	}

	@RequestMapping(value = "visitor/share")
	public String share() {
		WebAd xyfx = webAdService.findAdByCloNameOne("学员分享banner");
		WebUtil.setRequestAttribute("xyfx", xyfx);
		return "/visitor/share";
	}

	@RequestMapping(value = "visitor/article")
	public String article(Long id) {
		WebUtil.setRequestAttribute("art", artService.findById(id));
		return "/visitor/article";
	}

}